import request from '@/utils/request'

export const getUserMsg = (data) => {
  return request({
    url: '/api/reg',
    method: 'POST',
    data: data
  })
}

export const userLogin = (data) => {
  return request({
    url: '/api/login',
    method: 'POST',
    data: data
  })
}

export const userInfo = () => {
  return request({
    url: '/my/userinfo',
    headers: {
      // eslint-disable-next-line no-undef
      Authorization: localStorage.getItem('token')
    }
  })
}

export const changeUserMsg = (data) => {
  return request({
    url: '/my/userinfo',
    method: 'PUT',
    data: data,
    headers: {
      // eslint-disable-next-line no-undef
      Authorization: localStorage.getItem('token')
    }
  })
}

export const changeUserPic = (data) => {
  return request({
    url: '/my/update/avatar',
    method: 'PATCH',
    data: data,
    headers: {
      // eslint-disable-next-line no-undef
      Authorization: localStorage.getItem('token')
    }
  })
}

export const changeUserPass = (data) => {
  return request({
    url: '/my/updatepwd',
    method: 'PATCH',
    data: data,
    headers: {
      // eslint-disable-next-line no-undef
      Authorization: localStorage.getItem('token')
    }
  })
}

export const getArticleClassification = () => {
  return request({
    url: '/my/cate/list',
    headers: {
      // eslint-disable-next-line no-undef
      Authorization: localStorage.getItem('token')
    }
  })
}

export const addArticle = (data) => {
  return request({
    url: '/my/cate/add',
    method: 'POST',
    data: data,
    headers: {
      // eslint-disable-next-line no-undef
      Authorization: localStorage.getItem('token')
    }
  })
}

export const getArticleMsg = ({ id }) => {
  return request({
    url: '/my/cate/info',
    method: 'GET',
    params: {
      id
    },
    headers: {
      // eslint-disable-next-line no-undef
      Authorization: localStorage.getItem('token')
    }
  })
}
export const changeArticleMsg = (data) => {
  return request({
    url: '/my/cate/info',
    method: 'PUT',
    data: data,
    headers: {
      // eslint-disable-next-line no-undef
      Authorization: localStorage.getItem('token')
    }
  })
}

export const deleteArticleMsg = (data) => {
  return request({
    url: '/my/cate/del',
    method: 'DELETE',
    params: data,
    headers: {
      // eslint-disable-next-line no-undef
      Authorization: localStorage.getItem('token')
    }
  })
}

export const uploadArticle = (fd) => {
  return request({
    url: '/my/article/add',
    method: 'POST',
    data: fd,
    headers: {
      // eslint-disable-next-line no-undef
      Authorization: localStorage.getItem('token')
    }
  })
}

// eslint-disable-next-line camelcase
export const getArticleList = ({ pagenum, pagesize, cate_id, state }) => {
  return request({
    url: '/my/article/list',
    params: {
      pagenum,
      pagesize,
      cate_id,
      state
    },
    headers: {
      // eslint-disable-next-line no-undef
      Authorization: localStorage.getItem('token')
    }
  })
}

export const getArticleDetailMsg = (id) => {
  return request({
    url: '/my/article/info',
    params: {
      id
    },
    headers: {
      // eslint-disable-next-line no-undef
      Authorization: localStorage.getItem('token')
    }
  })
}

export const delArticleAPI = (id) => {
  return request({
    url: '/my/article/info',
    method: 'DELETE',
    params: {
      id
    },
    headers: {
      // eslint-disable-next-line no-undef
      Authorization: localStorage.getItem('token')
    }
  })
}
